//
// Created by baigui on 21-6-29.
//

#ifndef SIMPLE_PLAYER_MEDIAPLAYER_H
#define SIMPLE_PLAYER_MEDIAPLAYER_H


#include <pthread.h>
#include <log.h>

#include "Demux.h"
#include "VideoDecoder.h"
#include "VideoRender.h"

using namespace std;

class Demux;
class VideoDecoder;
//class AudioDecoder;
class VideoRender;

enum RenderType{
    Auto = 1,
    NDKCodecType = 2
};


class MediaPlayer : public enable_shared_from_this<MediaPlayer>{

public:

    MediaPlayer(){
        LOGE("new MeMediaPlayer");
    }
    ~MediaPlayer(){
        LOGV("~MeMediaPlayer");
    }
    void setDataSource(const char *path);
//    void setSurface(Surface surface)
    void start();
    void pause();
    void stop();

    int LoadRender(RenderType type = Auto);

    int setSurface(ANativeWindow *window);

    VideoDecoder* getVideoDecoder(){
        return mVideoDecoder.get();
    }

    VideoRender *getVideoRender();

    ANativeWindow *getWindow(){
        return mWindow;
    }

private:
    shared_ptr<Demux> mDumex;
    shared_ptr<VideoDecoder> mVideoDecoder;
    shared_ptr<VideoDecoder> mAudioDecoder;
    shared_ptr<VideoRender> mVideoRender;
    ANativeWindow *mWindow;
    pthread_mutex_t lock;

    void LoadDecoder(shared_ptr<MediaStream> steam);

    void LoadDemux();

    void LoadRender(int32_t type);

    void loadDemux(char *path);
};



#endif //SIMPLE_PLAYER_MEDIAPLAYER_H
